package com.qfedu.service.impl;

import com.qfedu.dao.UserDao;
import com.qfedu.exception.PasswordIncorrectException;
import com.qfedu.exception.UnkownUsernameException;
import com.qfedu.pojo.User;
import com.qfedu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserDao userDao;

    @Override
    public User login(String username,String pasword) throws Exception {
        //用户名是否为空
        if (username.equals("") || username == null){
            throw new UnkownUsernameException();
        }
        User user = userDao.login(username);
        if (user == null){
            throw new UnkownUsernameException();
        }
        System.out.println(user.getPassword());
        if (!pasword.equals(user.getPassword())){
            throw new PasswordIncorrectException();
        }
        return user;

    }

    @Override
    public int rgister(User user) {
        int rgister = userDao.rgister(user);
        return rgister;
    }
}
